﻿CREATE PROCEDURE [dbo].[Forum_Thread_Crumb]
	@hashTag NVARCHAR(64)
AS
BEGIN
	SET @hashTag = LTRIM(RTRIM(LOWER(@hashTag)))

	DECLARE @parentSectionId SMALLINT, @leftKey INT, @rightKey INT, @sectionId SMALLINT

	SELECT @parentSectionId = [ParentSectionId], @leftKey = [LeftKey], @rightKey = [RightKey], @sectionId = [SectionId]
	FROM [dbo].[forum_Section]
	WHERE [HashTag] = @hashTag

	SELECT [SectionId]
				,[ParentSectionId]
				,[LeftKey]
				,[Level]
				,[HashTag]
				,[Name]
	FROM [dbo].[forum_Section]
	WHERE [LeftKey] < @leftKey AND [RightKey] > @rightKey AND [Level] <> 0

	UNION ALL

	SELECT [SectionId]
				,[ParentSectionId]
				,[LeftKey]
				,[Level]
				,[HashTag]
				,[Name]
	FROM [dbo].[forum_Section]
	WHERE [ParentSectionId] = @parentSectionId

END
GO